<?php

	class Instructor
	{
		public $account;
		public $school = array();
		public $course = array();
		public $clasz = array();
		public $scheme = array();
		public $template = array();



		function gatherinfo($account_id)
		{
			$read = mysql_query("SELECT * FROM account WHERE account_id = $account_id") or die(mysql_error());

			while($row = mysql_fetch_assoc($read))
			{
				$this->account = $row;	
			}
		}


		function gatherschool($account_id)
		{
			$read = mysql_query("SELECT * FROM school WHERE account_id = $account_id") or die(mysql_error());
			$count = 0;
	
			while($row = mysql_fetch_assoc($read))
			{
				$this->school[$count] = $row;	
				$count++;
			}
		}


		function gathercourse($account_id)
		{
			$read = mysql_query("SELECT * FROM course WHERE account_id = $account_id") or die(mysql_error());
			$count = 0;
	
			while($row = mysql_fetch_assoc($read))
			{
				$this->course[$count] = $row;	
				$count++;
			}
		}

		
		function gatherclass($account_id)
		{
			$read = mysql_query("SELECT * FROM class WHERE account_id = $account_id") or die(mysql_error());
			$count = 0;
	
			while($row = mysql_fetch_assoc($read))
			{
				$this->clasz[$count] = $row;	
				$count++;
			}
		}

		
		function gatherscheme($account_id)
		{
			$block = array();
			$read1 = mysql_query("SELECT * FROM scheme WHERE account_id = $account_id") or die(mysql_error());
			$count1 = 0;
	
			while($row1 = mysql_fetch_assoc($read1))
			{
				$scheme_id = $row1['scheme_id'];
				$read2 = mysql_query("SELECT * FROM block WHERE scheme_id = $scheme_id") or die(mysql_error());
				$count2 = 0;
				
				while($row2 = mysql_fetch_assoc($read2))
				{
					$block[$count2]=$row2;
					$count2++;
				}

				$this->scheme[$count1] = $block;				
				$count1++;
			}
		}

		
		function gatherall($account_id)
		{
			$this->gatherinfo($account_id);
			$this->gatherschool($account_id);
			$this->gathercourse($account_id);
			$this->gatherclass($account_id);
			$this->gatherscheme($account_id);
		}


		function test()
		{
			echo "email = ".$this->account['username']."<br>";

			$i = 0;
			while($i<sizeof($this->school))
			{
				echo "school # $i : ";
				echo "school_name = ".$this->school[$i]['school_name'];
				echo "<br>";
				$i++;
			}

			$i = 0;
			while($i<sizeof($this->course))
			{
				echo "course # $i : ";
				echo "course_name = ".$this->course[$i]['course_name'];
				echo "<br>";
				$i++;
			}

			$i = 0;
			while($i<sizeof($this->clasz))
			{
				echo "class # $i : ";
				echo "class_name = ".$this->clasz[$i]['class_name'];
				echo "<br>";
				$i++;
			}

			$i = 0;
			while($i<sizeof($this->scheme))
			{
				$j = 0;
				echo "scheme # $i : ";
				
				while($j<sizeof($this->scheme[$i]))
				{
					echo $this->scheme[$i][$j]['lower_condition'];
					echo $this->scheme[$i][$j]['lower_bound'].",";
					echo $this->scheme[$i][$j]['upper_bound'];
					echo $this->scheme[$i][$j]['upper_condition'];
					$j++;
				}
				
				echo "<br>";
				$i++;
			}
		}
	}

?>
